<?
class ListProviderForm extends Form
{
	function ListProviderForm()
	{
        CGlobal::$website_title = "Danh sách Nhà cung cấp";
		Form::Form('ListProviderForm');
        $this->link_css("style/paging.css");
        $this->link_css("style/provider.css");
	}
	
	function on_submit()
	{
	}
	
	function draw()
	{
		global $display;
        $display->add("WEB_DIR",WEB_DIR);
        $item_per_page = 10;
		$this->beginForm(false,"post",false,Url::build_current());
        $total_provider = Db_Provider::total();

        $con_arr = array();
        
        $provider_status = Url::getInt("provider_status",1);
        $display->add('provider_status', $provider_status);
        if($provider_status!==0){
            $con_arr[] = "(status=$provider_status)";
        }

        $provider_id = Url::get("provider_id",'');
        $display->add('provider_id', $provider_id);
        if($provider_id){
            $con_arr[] = '(id='.(int)$provider_id.')';
        }

        $provider_name = Url::get("provider_name",'');
        $display->add('provider_name', $provider_name);
        if($provider_name){
            $con_arr[] = '(MATCH (`name`) AGAINST("'.DB::escape($provider_name).'"))';
        }

        $provider_desc = Url::get("provider_desc",'');
        $display->add('provider_desc', $provider_desc);
        if($provider_desc){
            $con_arr[] = '(MATCH (`desc`) AGAINST("'.DB::escape($provider_desc).'"))';
        }

        $provider_email = Url::get("provider_email",'');
        $display->add('provider_email', $provider_email);
        if($provider_email){
            $con_arr[] = '(`email` LIKE "%'.DB::escape($provider_email).'%")';
        }

        $provider_website = Url::get("provider_website",'');
        $display->add('provider_website', $provider_website);
        if($provider_website){
            $con_arr[] = '(`website` LIKE "%'.DB::escape($provider_website).'%")';
        }

        $provider_company = Url::get("provider_company",'');
        $display->add('provider_company', $provider_company);
        if($provider_company){
            $con_arr[] = '(`company` LIKE "%'.DB::escape($provider_company).'%")';
        }

        $provider_address = Url::get("provider_address",'');
        $display->add('provider_address', $provider_address);
        if($provider_address){
            $con_arr[] = '(`address` LIKE "%'.DB::escape($provider_address).'%")';
        }

        $provider_tel = Url::get("provider_tel",'');
        $display->add('provider_tel', $provider_tel);
        if($provider_tel){
            $con_arr[] = '((`tel` LIKE "%'.DB::escape($provider_tel).'%") OR (`mobile` LIKE "%'.DB::escape($provider_tel).'%") OR (`fax` LIKE "%'.DB::escape($provider_tel).'%"))';
        }
        
        $condition = implode($con_arr,' AND ');

        $page_no = (Url::getInt('page_no')<=1)?0:(Url::getInt('page_no')-1);
        $offset = $page_no*$item_per_page;
        $provider = Db_Provider::getProviders("$offset,$item_per_page",$condition);
        $display->add('server_img',IMAGE_PATH);
		$display->add('items',$provider);
        $display->add('paging', ECPaging::pagingSE($limit, $total_provider, $item_per_page,10, 'page_no',1));
		$display->add('total_row',$total_provider);
		$display->output('ProviderList');
		$this->endForm();
	}
}
?>